<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/14 0014
 * Time: 下午 13:24
 */

use yii\helpers\Html;

$this->title = $activity->title;
?>

<style type="text/css">

    .box {
        display: flex;
        flex-wrap: wrap;
    }

    .box-item {
        width: 50%;
        padding: 5px;
    }

    .box-item .player {
        background-color: white;
    }

    .box .box-item:nth-child(2n) {
        padding-right: 0;
    }

    .box .box-item:nth-child(2n+1) {
        padding-left: 0;
    }

    .more {
        color: #ffffff;
    }

</style>

<?= \frontend\widgets\Swiper::widget(['model' => $activity]) ?>

<div class="container-fluid">

    <?= \frontend\widgets\PlayerSearch::widget(['activity' => $activity]) ?>

    <div class="row statics white-bg">
        <div class="col-xs-4">
            <div>
                <p><?= Yii::t('app.c2', 'Total View') ?></p>
                <?= $activity->view_number ?>
            </div>
        </div>
        <div class="col-xs-4">
            <div>
                <p><?= Yii::t('app.c2', 'Total Vote') ?></p>
                <?= $activity->vote_number ?>
            </div>
        </div>
        <div class="col-xs-4">
            <div>
                <p><?= Yii::t('app.c2', 'Total Share') ?></p>
                <?= $activity->share_number ?>
            </div>
        </div>

    </div>

    <?= \frontend\widgets\CounterDown::widget(['activity' => $activity]) ?>

    <div class="box">
        <?php foreach ($players as $item): ?>
            <div class="box-item">
                <div class="card">
                    <img class="card__picture" src="<?= $item->getThumbnailUrl() ?>" alt="">
                    <div class="card-infos">

                        <p class="card__text">
                            <?= $item->title ?>
                        </p>
                        <div class="card__title">
                            <?= Yii::t('app.c2', '{s1} Votes', ['s1' => $item->total_vote_number]) ?>
                            <span class="card__id"></span>
                            <a href="/player/<?= $item->player_code ?>"
                               class="myButton"><?= Yii::t('app.c2', 'Vote It') ?></a>
                            <div style="clear: both"></div>
                        </div>

                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>

    <div style="text-align: center">
        <?= \yii\helpers\Html::a(Yii::t('app.c2', 'More Players'), ['/players', 'vasc' => $activity->seo_code], ['class' => 'btn btn-link more']); ?>
    </div>

</div>

<?php

$js = <<<JS

// document.querySelector('#sortable').sortablejs()
JS;
$this->registerJs($js);
?>

<script type="text/javascript">
    wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
        //shareData 参数记得为字符串类型
        var shareData = {
            title: '<?= $activity->title ?>',
            desc: '',//这里请特别注意是要去除html
            link: '<?= FRONTEND_BASE_URL . Yii::$app->request->url ?>',//域名必须JS安全域名
            imgUrl: '<?= $activity->getThumbnailUrl() ?>',
            success: function () {
                //$.post('/activity-share', {'id': '<?//= $activityModel->id ?>//',}, function (res) {
                //    console.log(1);
                //})
            },
            cancel: function () {
                console.log('cancel')
            }
        };

        if (wx.onMenuShareAppMessage) { //微信文档中提到这两个接口即将弃用，故判断
            wx.onMenuShareAppMessage(shareData);//1.0 分享到朋友
            wx.onMenuShareTimeline(shareData);//1.0分享到朋友圈
        } else {
            wx.updateAppMessageShareData(shareData);//1.4 分享到朋友
            wx.updateTimelineShareData(shareData);//1.4分享到朋友圈
        }

    });
</script>